Skip to content

fix: propagate options parameter across all controller methods - #11146

Open
aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:fix/pass-options
Open

aaqilniz wants to merge 1 commit into
loopbackio:masterfrom
aaqilniz:fix/pass-options

Conversation

@aaqilniz

@aaqilniz aaqilniz commented Aug 18, 2025 •

Copy link
Copy Markdown
Contributor

This PR updates defineCrudRestController to forward the controller-level options configuration to all underlying repository methods.

Previously, none of the CRUD REST controller methods were passing the options parameter down to their respective repository calls, meaning any configuration, transaction contexts, or execution options available at the controller level were entirely dropped.

Changes Made

Updated all generated CRUD controller methods that were not forwarding the options to forward the closure-scoped options parameter to the corresponding repository methods at the correct argument offsets.

Added unit tests verifying correct options propagation and argument positioning across repository method calls.

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 17044955138

Details

  • 1 of 2 (50.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 54.475%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/rest-crud/src/crud-rest.controller.ts 1 2 50.0%
Totals Coverage Status
Change from base Build 17030337281: 0.0%
Covered Lines: 9572
Relevant Lines: 12457

💛 - Coveralls

@dhmlau

dhmlau commented Sep 22, 2025

Copy link
Copy Markdown
Member

@aaqilniz, thanks for the PR. Could you please add tests? Thanks.

@dhmlau dhmlau added the need-tests Need to add tests in the PR label Sep 22, 2025
@aaqilniz
aaqilniz marked this pull request as draft October 18, 2026 04:41
@aaqilniz aaqilniz changed the title fix: pass options to repository methods fix: propagate options parameter across all controller methods Oct 31, 2026
@aaqilniz
aaqilniz marked this pull request as ready for review October 31, 2026 05:03
@aaqilniz

Copy link
Copy Markdown
Contributor Author

Hi, @dhmlau. Can you please have a look at the PR now? I have added tests to verify the changes. Thanks.

Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>

@samarpanB samarpanB left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am requesting changes because the PR forwards controller configuration into repository operation options, which crosses architectural responsibilities and does not demonstrate propagation of any request-scoped context. Please see the inline review for details.

filter?: Filter<T>,
): Promise<(T & Relations)[]> {
return this.repository.find(filter);
return this.repository.find(filter, options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned about the design of this change.

The options argument passed to defineCrudRestController() is controller configuration (basePath, readonly), not repository operation options.

By forwarding this object to every repository method, we're mixing REST-layer configuration with data-access concerns.

The PR description mentions transaction contexts and execution options, but I don't see how those would be available through this static controller configuration.

Could we clarify the actual use case this is intended to solve? If we need to propagate request-specific repository options, they should come from an appropriate execution context rather than the controller's configuration.

I'm also not seeing why this change is required for the referencesMany filtering issue. Can we demonstrate that dependency before making a cross-cutting change to all CRUD operations?

I would suggest reconsidering the approach rather than forwarding the existing options object.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need-tests Need to add tests in the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants